﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Coleotrack.Core.Helper;
using NUnit.Framework;

namespace Coleotrack.Test.Helper
{
    [TestFixture]
    public class StringHelperTest
    {
        #region Md5

        [Test]
        public void Null_Value_Should_Produce_Valid_Md5()
        {
            string text = null;
            string md5 = text.Md5();
            Assert.IsNotNullOrEmpty(md5);
            Assert.AreEqual(md5.Length, 32);
        }

        [Test]
        public void Empty_String_Should_Produce_Valid_Md5()
        {
            string text = string.Empty;
            string md5 = text.Md5();
            Assert.IsNotNullOrEmpty(md5);
            Assert.AreEqual(md5.Length, 32);
        }

        #endregion

        #region Email validation

        [Test]
        public void Valid_Email_Address_Should_Pass_Validation()
        {
            const string email = "me@example.com";
            bool valid = email.IsValidEmailAddress();
            Assert.IsTrue(valid);
        }

        [Test]
        public void Email_Address_With_Sub_Domain_Should_Pass_Validation()
        {
            const string email = "me@sub.example.com";
            bool valid = email.IsValidEmailAddress();
            Assert.IsTrue(valid);
        }

        [Test]
        public void Email_Address_With_Numbers_Should_Pass_Validation()
        {
            const string email = "me2@mail4u.com";
            bool valid = email.IsValidEmailAddress();
            Assert.IsTrue(valid);
        }

        [Test]
        public void Email_Address_With_Umlaut_Should_Pass_Validation()
        {
            const string email = "mäpp@fälschlicherweise.de";
            bool valid = email.IsValidEmailAddress();
            Assert.IsTrue(valid);
        }

        [Test]
        public void Null_Value_As_Email_Should_Not_Pass_Validation()
        {
            const string email = null;
            bool valid = email.IsValidEmailAddress();
            Assert.IsFalse(valid);
        }

        [Test]
        public void Empty_String_As_Email_Should_Not_Pass_Validation()
        {
            string email = string.Empty;
            bool valid = email.IsValidEmailAddress();
            Assert.IsFalse(valid);
        }

        [Test]
        public void Word_As_Email_Should_Not_Pass_Validation()
        {
            const string email = "missing";
            bool valid = email.IsValidEmailAddress();
            Assert.IsFalse(valid);
        }

        [Test]
        public void Email_Without_Top_Level_Domain_Should_Not_Pass_Validation()
        {
            const string email = "something@missing";
            bool valid = email.IsValidEmailAddress();
            Assert.IsFalse(valid);
        }

        [Test]
        public void Email_With_Invalid_Top_Level_Domain_Should_Not_Pass_Validation()
        {
            const string email = "something@missing.c";
            bool valid = email.IsValidEmailAddress();
            Assert.IsFalse(valid);
        }

        [Test]
        public void Email_Without_Username_Should_Not_Pass_Validation()
        {
            const string email = "@missing.com";
            bool valid = email.IsValidEmailAddress();
            Assert.IsFalse(valid);
        }

        #endregion

        #region Text validation

        [Test]
        public void Word_Should_Pass_Validation()
        {
            const string text = "Hello";
            bool valid = text.IsNotEmptyText();
            Assert.IsTrue(valid);
        }

        [Test]
        public void Word_With_Leading_Spaces_Should_Pass_Validation()
        {
            const string text = "  Go";
            bool valid = text.IsNotEmptyText();
            Assert.IsTrue(valid);
        }

        [Test]
        public void Null_Should_Not_Pass_Validation()
        {
            const string text = null;
            bool valid = text.IsNotEmptyText();
            Assert.IsFalse(valid);
        }

        [Test]
        public void Empty_String_Should_Not_Pass_Validation()
        {
            string text = string.Empty;
            bool valid = text.IsNotEmptyText();
            Assert.IsFalse(valid);
        }

        [Test]
        public void String_Without_Content_Should_Not_Pass_Validation()
        {
            const string text = "";
            bool valid = text.IsNotEmptyText();
            Assert.IsFalse(valid);
        }

        [Test]
        public void String_Only_Containing_Spaces_Should_Not_Pass_Validation()
        {
            const string text = "  ";
            bool valid = text.IsNotEmptyText();
            Assert.IsFalse(valid);
        }

        #endregion
    }
}
